package itheima.moc.TestServerSocketDemo8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class ServerSocketDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(5555);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                5,      //核心线程数量
                8,//线程池的总数量
                60,     //临时线程空闲时间
                TimeUnit.SECONDS,       //临时线程空闲时间单位
                new ArrayBlockingQueue<>(2),    //阻塞队列
                Executors.defaultThreadFactory(),   //创建线程池方式
                new ThreadPoolExecutor.AbortPolicy() //任务拒绝策略
                );
        //从网络中接受读取到的流
        while (true) {
            Socket accept = ss.accept();
            Threadpool threadpool = new Threadpool(accept);
//            new Thread(threadpool).start();
            pool.submit(threadpool);
        }
        //循环读取后服务器就不需要关闭了
//        ss.close();


    }
}
